package ttu.eclass.DBServer;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class MoodleDatabase {
	private String hostIP = "localhost";
	private String schemaName = "moodle";
	private String username = "root";
	private String password = "root";
	private Connection connection=null;
	private Statement statement=null;
	public MoodleDatabase() {
		try {
			connection = DriverManager.getConnection("jdbc:mysql://" + hostIP
					+ "/" + schemaName, username, password);
			statement = connection.createStatement();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public MoodleDatabase(String hostIP, String schemaName, String username,
			String password) {
		super();
		this.hostIP = hostIP;
		this.schemaName = schemaName;
		this.username = username;
		this.password = password;
		try {
			connection = DriverManager.getConnection("jdbc:mysql://" + hostIP
					+ "/" + schemaName, username, password);
			statement = connection.createStatement();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public ResultSet query(String sql){
		ResultSet resultSet=null;
		try {
			resultSet = statement.executeQuery(sql);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return resultSet;
	}
	public void update(String sql){
		try {
			statement.executeUpdate(sql);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	public String getSchemaName() {
		return schemaName;
	}
	public void setSchemaName(String schemaName) {
		this.schemaName = schemaName;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getHostIP() {
		return hostIP;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
}
